package com.tjbklx1.thread.chap08.demo02;

import java.util.Random;
import java.util.concurrent.ExecutorService;

public class ClientThread extends Thread {

//	private final Channel channel;
	private final ExecutorService executorService;
	private static final Random random = new Random();

//	public ClientThread(String name, Channel channel) {
//		super(name);
//		System.out.println(name);
//		this.channel = channel;
//	}
	public ClientThread(String name,ExecutorService executorService) {
		super(name);
		System.out.println(name);
		this.executorService = executorService;
	}

	@Override
	public void run() {
		try {
			for (int i = 0; true; i++) {
				Request request = new Request(getName(), i);
//				channel.putRequest(request);
				executorService.execute(request);
				System.out.println(getName()+" put reuqest");
				Thread.sleep(random.nextInt(1000));
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
